
from lxml import etree

# 控制返回类型，这样就会有提示了 -> requests.get
import requests
import time
import random
from fakeagent import get_fake_ua, get_fake_p


def get_html(url) -> requests.get:
    time.sleep(1)
    res = requests.get(url=url, headers=get_fake_ua(), proxies=get_fake_p())
    print(res.status_code)
    if res.status_code == 200:
        return res
    else:
        get_html(url)


def parse(res):
    xpd = etree.HTML(res.text)
    urls = xpd.xpath('//ul[@class="rank-list"]/li//div[@class="info"]/a/@href')
    urls = ["https://api.bilibili.com/x/web-interface/view?bvid=" + str(i).split("/")[-1] for i in urls]
    # print(urls)
    for url in urls:
        print(url)
        get_html(url)


def main():
    # res = get_html("https://www.bilibili.com/v/popular/rank/all")
    # parse(res)
    pass


if __name__ == '__main__':
    main()

